<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
                template="/resources/template/template.xhtml"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:p="http://primefaces.org/ui"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:pa="http://java.sun.com/jsf/composite/paymentMethod"
                xmlns:ph="http://java.sun.com/jsf/composite/pharmacy">

    <ui:define name="content">
        <h:form>
            <h:outputStylesheet library="css" name="pharmacyA4.css"/>
            <h:panelGroup rendered="#{!saleReturnController.printPreview}" styleClass="alignTop" >
                <p:panel>

                    <f:facet name="header" >      

                        <h:panelGrid columns="15"  >                           
                            <h:outputLabel value="&nbsp;&nbsp;&nbsp;&nbsp;" style="min-width: 50px;" />

                            <p:selectOneMenu  id="cmbPs"
                                              value="#{saleReturnController.returnBill.paymentMethod}">     
                                <f:selectItems value="#{enumController.paymentMethods}"  />
                                <p:ajax process="cmbPs" update="creditCard cheque slip" 
                                        event="change" />
                            </p:selectOneMenu>
                            <p:inputText value="#{saleReturnController.comment}" id="comment"/>
                            <p:watermark value="Comment" for="comment"/>

                            <h:panelGroup id="creditCard" style="display: #{saleReturnController.returnBill.paymentMethod ne 'Card' ? 'none' : 'block'} ; ">
                                <pa:creditCard paymentMethodData="#{saleReturnController.paymentMethodData}"/>
                            </h:panelGroup>

                            <h:panelGroup id="cheque" style="display: #{saleReturnController.returnBill.paymentMethod ne 'Cheque' ? 'none' : 'block'} ; " >
                                <pa:cheque paymentMethodData="#{saleReturnController.paymentMethodData}"/>
                            </h:panelGroup>

                            <h:panelGroup id="slip" style="display: #{saleReturnController.returnBill.paymentMethod ne 'Slip' ? 'none' : 'block'} ;">
                                <pa:slip paymentMethodData="#{saleReturnController.paymentMethodData}"/>
                            </h:panelGroup>

                            <p:commandButton  value="Return" action="#{saleReturnController.settle}" 
                                              onclick="onSubmitButton();"
                                              ajax="false"  style="width: 150px; padding: 1px;border: 1px solid ; margin: auto;"
                                              rendered="#{webUserController.hasPrivilege('PharmacySaleReturn')}">
                            </p:commandButton>
                            <p:outputLabel  value="Recievable Amount" /> 
                            <p:outputLabel id="total"  value="#{saleReturnController.returnBill.total}" style="float: right;"/>

                        </h:panelGrid>
                    </f:facet>
                </p:panel>

                <p:dataTable var="ph" value="#{saleReturnController.billItems}"
                             scrollable="true" scrollHeight="250"
                             id="itemList" >  

                    <f:facet name="header">  
                        Returning Item 
                    </f:facet>  


                    <p:column headerText="Item Name" style="width:50px!important;">  

                        <h:outputText value="#{ph.item.name}"  />                     

                    </p:column>  

                    <p:column headerText="Ballance Qty in Unit" style="width:25px!important;"> 
                        <h:outputText value="#{ph.pharmaceuticalBillItem.qty}" />                   
                    </p:column>  

                    <p:column headerText="Purchase Rate" style="width:25px!important;"> 
                        <h:outputText value="#{ph.rate}"  />                        
                    </p:column>                 


                    <p:column headerText="Bathch No" style="width:25px!important;">                       
                        <h:outputText value="#{ph.pharmaceuticalBillItem.stringValue}" />                        
                    </p:column>  

                    <p:column headerText="Date of Expirey" style="width:25px!important;">                     
                        <h:outputText value="#{ph.pharmaceuticalBillItem.doe}" /> 
                    </p:column>


                    <p:column headerText="Returning Qty in Unit" style="width:25px!important;">                     
                        <p:inputText autocomplete="off" value="#{ph.qty}" >
                            <f:ajax event="blur" render="@this :#{p:component('total')}"  execute="@this" listener="#{saleReturnController.onEdit(ph)}" ></f:ajax>
                        </p:inputText>
                    </p:column>  

                </p:dataTable>  
                <p:spacer height="50"/>

            </h:panelGroup>

            <p:panel rendered="#{saleReturnController.printPreview}">
                <p:commandButton ajax="false" action="pharmacy_search_sale_bill" value="Phrmacy Sale Search" actionListener="#{saleReturnController.makeNull}"/>                    
                <p:commandButton value="Print" ajax="false" action="#" >
                    <p:printer target="gpBillPreview" ></p:printer>
                </p:commandButton>
                <!--                <p:panel   id="gpBillPreview"   >
                                    <ph:returnBill bill="#{saleReturnController.returnBill}"/>
                
                                </p:panel>-->

                <h:panelGroup   id="gpBillPreview"  > 

                    <h:panelGroup   id="gpBillPreviewSingle" rendered="true">

                        <div >
                            <h:panelGroup rendered="true" > 
                                <ph:saleBill bill="#{saleReturnController.returnBill}"></ph:saleBill>
                            </h:panelGroup>
                        </div>

                    </h:panelGroup>

                    <h:panelGroup id="gpBillPreviewDouble" rendered="#{sessionController.loggedPreference.pharmacyBillPaperType eq 'PosPaper'}"> 

                        <div >
                            <h:panelGroup     rendered="#{sessionController.loggedPreference.pharmacyBillPrabodha eq true}"> 
                                <ph:saleBill_prabodha bill="#{saleReturnController.returnBill}"></ph:saleBill_prabodha>
                            </h:panelGroup>
                        </div>

                    </h:panelGroup>

                    <h:panelGroup id="gpBillPreviewFiveFive" rendered="#{sessionController.loggedPreference.pharmacyBillPaperType eq 'FiveFivePaper'}"> 

                        <div >
                            <h:panelGroup rendered="#{sessionController.loggedPreference.pharmacyBillPrabodha eq false}" > 
                                <ph:saleBill_five_five bill="#{saleReturnController.returnBill}"></ph:saleBill_five_five>
                            </h:panelGroup>
                        </div>

                    </h:panelGroup>

                </h:panelGroup>
            </p:panel>

        </h:form>
    </ui:define>  

</ui:composition>
